package com.night.icm.controller.business;

import com.night.icm.common.utils.PageDataDTO;
import com.night.icm.model.business.StudentCreditRecordDTO;
import com.night.icm.service.business.service.StudentCreditRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
 * StudentCreditRecordController
 *
 * @author Liao ZhiYong
 * @date 2020/3/22
 */
@Api(tags = "学生学分记录管理")
@RestController
@RequestMapping("/api/icm-credit-record")
public class StudentCreditRecordController {

    private StudentCreditRecordService studentCreditRecordService;

    @Autowired
    public StudentCreditRecordController(StudentCreditRecordService studentCreditRecordService) {
        this.studentCreditRecordService = studentCreditRecordService;
    }

    @ApiOperation(value = "分页查找学生学分记录")
    @GetMapping(value = "")
    public PageDataDTO<StudentCreditRecordDTO> findOnePage(
            @ApiParam(value = "页号，从0开始", required = true, defaultValue = "0") @RequestParam("page") @Min(0) int page,
            @ApiParam(value = "每页记录条数", required = true, defaultValue = "30") @RequestParam("size") @Min(1) @Max(100) int size,
            @ApiParam(value = "排序字段，例如：字段1,asc,字段2,desc") @RequestParam(value = "sort", required = false, defaultValue = "id,desc") String sort,
            @ApiParam(value = "学院名称") @RequestParam(value = "academyId", required = false) String academyId,
            @ApiParam(value = "专业名称") @RequestParam(value = "professionId", required = false) String professionId,
            @ApiParam(value = "班级名称") @RequestParam(value = "classId", required = false) String classId,
            @ApiParam(value = "学生姓名") @RequestParam(value = "studentName", required = false) String studentName,
            @ApiParam(value = "所属年级") @RequestParam(value = "grade", required = false) String grade
    ) {
        return this.studentCreditRecordService.findOnePage(page, size, sort, academyId, professionId, classId, studentName, grade);
    }

    @ApiOperation(value = "根据id查找学生学分记录")
    @GetMapping(value = "/{id}")
    public StudentCreditRecordDTO findById(@ApiParam(value = "学生学分记录id", required = true) @PathVariable(name = "id") String id) {
        return this.studentCreditRecordService.findById(id);
    }

    @ApiOperation(value = "根据学生学号查找学生学分记录")
    @GetMapping(value = "/code/{studentCode}")
    public StudentCreditRecordDTO findByStudentCode(@ApiParam(value = "学生code", required = true) @PathVariable(name = "studentCode") String studentCode) {
        return this.studentCreditRecordService.findByStudentCode(studentCode);
    }

    @ApiOperation(value = "提交学生学分记录")
    @PutMapping(value = "/{id}")
    public StudentCreditRecordDTO complete(
            @ApiParam(value = "学生学分记录id", required = true) @PathVariable(name = "id") String id,
            @ApiParam(value = "学生学分记录", required = true) @RequestBody @Validated StudentCreditRecordDTO studentCreditRecordDTO
    ) {
        return this.studentCreditRecordService.complete(id, studentCreditRecordDTO);
    }
}